Page({
  data: {
    infoData: null, // 数据
    starNum: 0, // 星星
    infoContent: '', // 简介信息
    unflodSwitch: false, // 展开开关
    id: 0, // 用于查询电影数据的id
  },
  onLoad: function(e) {
    console.log(e);
    let app = getApp();
    let self = this;
    console.log(app.globalData.xyData);
    let obj = null;
    if (e.type == 1) {
      obj = app.globalData.recommendData[e.index];
    } else if (e.type == 2) {
      obj = app.globalData.xyData[e.index];
    }

    if (e.id) {
      console.log(123);
      this.setData({
        id: e.id
      });
      wx.request({
        url: "https://douban.uieee.com/v2/movie/subject/" + e.id,
        header: {
          'content-type': 'json'
        },
        success: function(res) {
          obj = res.data;
          console.log(res.data);
          self.setData({
            infoData: obj,
            starNum: self.getStar(obj),
            infoContent: obj.summary.substring(0, 57) + '...'
          })
        }
      })
    } else {
      this.getStar(obj);
      this.setData({
        infoData: obj,
        starNum: this.getStar(obj),
        infoContent: obj.summary.substring(0, 57) + '...'
      })
    }
  },
  unflod: function() {
    this.setData({
      infoContent: this.data.infoData.summary,
      unflodSwitch: true
    })
  },
  getStar: function(data) {
    // 获取星星 好评
    let arr = [];
    let num = parseInt(data.rating.average);
    if (num === 7 || num === 6) {
      arr = [[1, 2, 3], [1, 2]];
    } else if (num === 8) {
      arr = [[1, 2, 3, 4], [1]];
    } else if (num === 9) {
      arr = [[1, 2, 3, 4, 5], []];
    } else if (num <= 5 && num > 2) {
      arr = [[1, 2], [1, 2, 3]];
    } else if (num <= 2) {
      arr = [[1], [1, 2, 3, 4]];
    }
    return arr;
  }
})